<?php
/**
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app
 * @since         CakePHP(tm) v 0.10.0.1076
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
 include_once 'config/database.php';
 $c_flag = new DATABASE_CONFIG; 
 mysql_connect($c_flag->default['host'],$c_flag->default['login'],$c_flag->default['password']);
 mysql_select_db($c_flag->default['database']);
/* Cron to ban the user from vieweing the project in which he didn't submit the assignment ontime 2 hours after locking it */
function bancron_flag( $id = null)
{
	$time_elapse = Configure::read('TimeElapseFlag'); /* put into a configuration */
	$sql_append = '';
	if(!empty($id))
	{
		/* for single user */
		$sql_append = " AND user_id = $id";	
	}
	
	/* for all the user if he locks and not submitted the assignment revision within $time_elapse time, he will be flagged */
	$sql = " UPDATE users SET status = 'flagged' WHERE id IN (SELECT user_id FROM `assignments` WHERE TIME_TO_SEC(TIMEDIFF(now(), `datetime_started`)) > $time_elapse AND status = 'revision' )".$sql_append;	
	mysql_query($sql);
	
	/* to make the assignment available  */
	$sql = "UPDATE assignments SET status = 'available' WHERE status = 'revision' AND TIME_TO_SEC(TIMEDIFF(now(), `datetime_started`)) > $time_elapse";
	mysql_query($sql);
	
}
$flag_id = '';
if(isset($_GET['id']))
{
	$flag_id = $_GET['id'];
}
bancron_flag($flag_id);